import { createStore, combineReducers } from 'redux';
import { persistReducer, persistStore } from 'redux-persist';
import asyncStorage from '@react-native-community/async-storage';
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'

// Reducer
import UserReducer from './UserReducer';
import GlobalReducer from './GlobalReducer';
import PublishReducer from './PublishReducer';


export default function ConfigStore () { 

    const RootReducer = combineReducers ({
        // 数据信息
        user: UserReducer,
        publish: PublishReducer,
        global: GlobalReducer
    });

    const persistConfig = {
        key: 'root',
        storage: asyncStorage, // storage
        stateReconciler: autoMergeLevel2,
        debug: false,
    };

    // 持久化存储Store
    const presistRootReducer = persistReducer(persistConfig, RootReducer);

    const store = createStore(presistRootReducer);
    const persistor = persistStore(store);

    
    return { store, persistor };

}